from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.forms import UserCreationForm, PasswordChangeForm, SetPasswordForm, UserChangeForm
from django.contrib.auth.forms import UsernameField

from django.contrib.auth.models import User

from django.forms import ModelForm

from django import forms

class LoginForm(AuthenticationForm):
    username = UsernameField(max_length=32, widget=forms.TextInput(attrs={'class': 'w3-input z1'}) )
    password = forms.CharField(max_length=32, widget=forms.PasswordInput(attrs={'class': 'w3-input z1'}) )

class RegistrationForm(UserCreationForm):
    email = forms.EmailField(
        max_length=64,
        widget=forms.EmailInput(attrs={'class': 'w3-input z1'}),
    )
    username = UsernameField(max_length=32, widget=forms.TextInput(attrs={'class': 'w3-input z1'}) )
    password1 = forms.CharField(
        label = 'Password',
        max_length=32,
        widget=forms.PasswordInput(attrs={'class': 'w3-input z1'})
    )
    password2 = forms.CharField(
        label = 'Confirm Password',
        max_length=32,
        widget=forms.PasswordInput(attrs={'class': 'w3-input z1'})
    )

    class Meta:
        model = User
        fields = ['email', 'username', 'password1', 'password2']

class PasswordUpdateForm(SetPasswordForm):

    new_password1 = forms.CharField(
        label = "New password",
        strip=False,
        widget = forms.PasswordInput(attrs={'class': 'w3-input z1'}),
    )
    new_password2 = forms.CharField(
        label = "Confirm new password",
        strip=False,
        widget = forms.PasswordInput(attrs={'class': 'w3-input z1'}),
    )

class UsernameChangeForm(ModelForm):
    #verify that this field cehcks if user exists
    username = UsernameField(max_length=32, widget=forms.TextInput(attrs={'class': 'w3-input z1'}) )
    class Meta:
        model = User
        fields = ['username', ]

class EmailChangeForm(ModelForm):
    email = forms.EmailField(
        max_length=64,
        widget=forms.EmailInput(attrs={'class': 'w3-input z1'}),
    )
    class Meta:
        model = User
        fields = ['email', ]
